<template>
    <SysDialog :title="dialog.title" :visible="dialog.visible" :width="dialog.width" :height="dialog.height"
        @onClose="onClose" @onConfirm="commit">
        <template v-slot:content>
            <el-form :model="addModel" ref="addFormRef" label-width="90px" :inline="false"
                size="default">
                <el-row :gutter="20">
                    <el-col :span="8" :offset="0">
                        <el-form-item prop="zhouBaoShiJian" label="周报时间">
                            <!-- <el-input v-model="addModel.zhouBaoShiJian"></el-input> -->
                             <el-date-picker v-model="addModel.zhouBaoShiJian" placeholder="请选择周报时间"></el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8" :offset="0">
                        <el-form-item prop="zhouBaoMingCheng" label="周报名称">
                            <el-input v-model="addModel.zhouBaoMingCheng"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="8" :offset="0">
                        <el-form-item prop="" label="周报内容">
                            <el-input v-model="addModel.zhouBaoNeiRong"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8" :offset="0">
                        <el-form-item prop="beizhu" label="周报备注">
                            <el-input v-model="addModel.beiZhu"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-form-item prop="beiZhu" label="备注">
                     <textarea  rows="5" cols="100" v-model="addModel.beiZhu"></textarea>
                </el-form-item>
                 
            </el-form>

        </template>
    </SysDialog>
</template>

<script setup lang="ts">

import SysDialog from '@/components/SysDialog.vue'
import useDialog from '@/hooks/useDialog';
import { nextTick, reactive, ref } from 'vue';
import { ElMessage, FormInstance } from 'element-plus';
import { addUserApi, editUserApi, getListApi } from '@/api/zb';
import { EditType, Title } from '@/type/BaseType';
import { ZbModel } from '@/api/zb/ZbModel';
const { dialog, onClose, onConfirm, onShow } = useDialog()     
const show = (type: string, row?: ZbModel) => { 
 
    type == EditType.ADD ? dialog.title = Title.ADD : dialog.title = Title.EDIT
    dialog.height = 500
    dialog.width = 1000
    dialog.visible = true
 
    if (row) {
        nextTick(() => {
            Object.assign(addModel, row)
            console.log('addModel:', addModel);
        })
    }
 
    addFormRef.value?.resetFields()
 
    addModel.type = type;
};
 
defineExpose({
    show
})
 
const addModel = reactive<ZbModel>({
    type: '',
    id: '',
    zhouBaoShiJian: '',
    zhouBaoMingCheng: '',
    zhouBaoNeiRong: '',
    beiZhu: '',

    
})
 
const addFormRef = ref<FormInstance>()

 
const emists = defineEmits(['onFresh'])   

 
const commit = () => {
    addFormRef.value?.validate(async (valid) => {
        if (valid) {
            let res = null;
            if (addModel.type == EditType.ADD) {
                res = await addUserApi(addModel);
            } else {
                res = await editUserApi(addModel);
            }
            console.log(res)
            if (res && res.code == 200) {
                ElMessage.success(res.msg)
                emists('onFresh')
                onClose()
            }
        }
    })
}
</script>
<style scoped></style>